from django.test import TestCase

# Create your tests here.
import requests
url = "http://127.0.0.1:8000/user/login/"

params = {
    "phone": "18438613151"
}
json_params = {
    'name':'mon',
    'password':'123',
    "phone":"18438613151",
    'sex':'男',
    'address':'上海',

}
# res.code text json() content
# resp = requests.get(url,params=params)
# res = requests.delete(url,)
# res = requests.post(url,json=json_params)
# print(resp.content)
# print(resp.text)

# 响应的数据类型： application/json,  text/html,  text/css,   application/javascript,
# 判断响应的数据类型是否为application/json
# if 'application/json' in resp.headers['Content-Type']:
#     resp_data = resp.json()
#     print(resp_data)
#     token = resp_data.get('token')
#     resp = requests.delete(url, headers={'Authorization': 'Token ' + token})
#     print(resp.json())
# else:
#     print(resp.text)

def geturl(path):
    return 'http://localhost:8000' + path


from unittest import TestCase
class AppUserTest(TestCase):
    def test_login(self):
        resp = requests.post(geturl('/users/'), json={
            'phone': '17791692095',
            'code': '1765',
            'auth_str': 'disen123'
        })
        print(resp.text)

    def test_list(self):
        resp = requests.get(geturl('/users/'))
        print(resp.text)

    # def test_retrieve(self):
    #     resp = requests.get(geturl('/api/student/1/'))
    #     print(resp.text)



